package support

import (
	"gin-skeleton/core/event"
	"gin-skeleton/core/logger"
	"gin-skeleton/etc"
	"gin-skeleton/support/db"
	"gin-skeleton/support/encrypt"
	"github.com/go-redis/redis/v8"
	"github.com/sirupsen/logrus"
	"github.com/spf13/viper"
	"gorm.io/gorm"
)

var (
	RedisClient *redis.Client
)

// Config 获取配置信息
func Config() *etc.Config {
	return etc.Load()
}
// Viper 配置对象
func Viper() *viper.Viper {
	return etc.Viper()
}

// Log 日志
func Log() *logrus.Entry {
	return logger.Get()
}

// MysqlDb Mysql连接实例
func MysqlDb(name string) *gorm.DB {
	return db.Mysql(name)
}

// Redis Redis连接实例
func Redis() *redis.Client {
	if RedisClient == nil {
		Log().Panicln("Redis Connection not enabled")
		return nil
	}

	return RedisClient
}

// RsaCrypt RSA 加解密工具
func RsaCrypt() *encrypt.Rsa {
	return encrypt.GetRSA()
}

// AesCrypt AES 加解密工具
func AesCrypt(key string) *encrypt.Aes {
	return encrypt.GetAes(key)
}

// Event 事件管理对象
func Event() *event.EventDispatcher{
	return event.GetEventDispatcher()
}